package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "购物车接口")
@Slf4j
@RequestMapping("/user/shoppingCart")
@RestController
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result shoppingCartAdd(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("----c端----添加购物车信息:{}",shoppingCartDTO);
        shoppingCartService.shoppingCartAdd(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> shoppingCartList(){
        log.info("----c端----查看购物车");
        List<ShoppingCart> list = shoppingCartService.shoppingCartList();
        return Result.success(list);
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result cleanShoppingCart(){
        log.info("----c端----清空购物车");
        shoppingCartService.cleanCartService();
        return Result.success();
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车的一个商品")
    public Result cleanOneShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("----c端----删除单一商品，商品信息为:{}",shoppingCartDTO);
        shoppingCartService.cleanOneShoppingCart(shoppingCartDTO);
        return Result.success();
    }


}
